package cmd

import (
	"fmt"
	"io/ioutil"
	"net/http"

	"github.com/spf13/cobra"
)

// diffCmd represents the diff command
var reloadCmd = &cobra.Command{
	Use: "reload",
	Run: func(cmd *cobra.Command, args []string) {
		client := http.Client{}
		req, err := http.NewRequest("GET", cmd_url_prefix+"/api/reload", nil)
		if err != nil {
			fmt.Printf("创建请求失败: %v\n", err)
			return
		}

		resp, err := client.Do(req)
		if err != nil {
			fmt.Printf("请求失败: %v\n", err)
			return
		}
		defer resp.Body.Close()
		buf, _ := ioutil.ReadAll(resp.Body)
		fmt.Print(string(buf))
	},
}

func init() {
	rootCmd.AddCommand(reloadCmd)
}
